package service.common;

import constant.table.ClazzConstact;
import entity.table.TableDto;
import enums.table.ClazzTypeEnum;

import java.util.List;

/**
 * 实体类
 */
public class CommonService {

    /**
     * 生成包路径
     * @param packstage 遵循驼峰规则
     * @return 返回值为 StringBuilder 对象
     * {@docroot}
     * -----------------------------------------------------------------------------------
     * <pre>{@code
     * 输入:
     * ringPackage("com.zoga.controller.entrust");
     *
     * 输出:
     * package com.zoga.controller.entrust;
     * </pre>}
     * -----------------------------------------------------------------------------------
     */

    /*public StringBuilder bringPackage(String packstage) {
        return new StringBuilder().append(ClazzConstact.PACKAGE).append(" ").append(packstage).append(";\n");
    }*/

    /**
     * 生成导入包
     * @param list 数组 List<String> 包含需要引入的包的路径名称
     * @return 返回值为 StringBuilder 对象
     * {@docroot}
     * -----------------------------------------------------------------------------------
     * <pre>{@code
     * 输入:
     * List<String> list = new ArrayList();
     * list.add("java.lang.String");
     * list.add("java.lang.Integer");
     * ringPackage(list);
     *
     * 输出:
     * import java.lang.String;
     * import java.lang.Integer;
     * </pre>}
     * -----------------------------------------------------------------------------------
     */
    /*public StringBuilder bringImport(List<String> list) {
        StringBuilder str = new StringBuilder("\n");
        // 遍历集合
        for (int i=0; i<list.size(); i++) {
            // 构造导入包的路径
            str.append(ClazzConstact.IMPORT).append(" ").append(list.get(i)).append(";\n");
        }
        return str;
    }*/

    /**
     * 生成类内容：包含开始与结束花括号
     * @param clazztype 类名字后缀，枚举：ClazzTypeEnum
     * @param tableName 表的实体类
     * @param body 类的内容
     * @return 返回类文件的主体内容
     * -----------------------------------------------------------------------------------
     * <pre>{@code
     * 输入:
     * bringBody(ClazzTypeEnum.VO, "User", "");
     *
     * 输出:
     * public class UserVo extends User {
     *     /**
     *      * 序列化
     *      * /
     *      private static final long serialVersionUID = 1L;
     * }
     * </pre>}
     * -----------------------------------------------------------------------------------
     */
    /*public String bringBody(ClazzTypeEnum clazztype, String tableName, String body) {
        StringBuilder str = new StringBuilder("");
        str.append("\npublic class ").append(tableName).append(clazztype.getSuffix()).append(" extends ").append(tableName).append(" {\n");

        // -------------------------------------------------------------------------------------------------------------
        // 序列化
        str.append(this.multiLineComments("\n\t", "序列化"));
        str.append("\n\tprivate static final long serialVersionUID = 1L;\n");

        // -------------------------------------------------------------------------------------------------------------
        // 主体内容
        str.append(body);

        // -------------------------------------------------------------------------------------------------------------
        str.append("}\n");
        return str.toString();
    }

    public String bringBodyBean(ClazzTypeEnum clazztype, String tableName, List<TableDto> filedList) {
        String clazzName = tableName + clazztype;
        return this.bringBody(clazztype, tableName, this.body(clazzName, filedList));
    }

    private String body(String clazzName, List<TableDto> filedList) {
        StringBuilder str = new StringBuilder();

        // 私有属性 -----------------------------------------------------------------------------------------------------
        for (TableDto dto : filedList) {
            str.append(this.multiLineComments("\n\t", dto.getColumnComment()))
                    .append("\n\tprivate ")
                    .append(dto.getDataType()).append(" ")
                    .append(dto.getColumnName())
                    .append(";\n");
        }

        // set get -----------------------------------------------------------------------------------------------------
        for (TableDto dto : filedList) {
            str.append(this.method("\n\t", dto.getColumnName(), dto.getDataType())).append("\n");
        }

        // toString ----------------------------------------------------------------------------------------------------
        str.append(this.methodStr("\n\t", clazzName, filedList)).append("\n");

        return str.toString();
    }*/

    /**
     * =================================================================================================================
     */

    /**
     * 多行注释
     * @param indentation 缩进
     * @param comment 注释内容
     * @return 返回一个多行注释
     * -----------------------------------------------------------------------------------
     * <pre>{@code
     *  输入:
     *  mmultiLineComments("\n\t", "序列化");
     *
     *  输出:
     *  /**
     *   * 序列化
     *   * /
     * </pre>}
     * -----------------------------------------------------------------------------------
     */
//    public StringBuilder multiLineComments(String indentation, String comment) {
//        StringBuilder str = new StringBuilder();
//        str.append(indentation).append("/**");
//        str.append(indentation).append(" * ").append(comment);
//        str.append(indentation).append(" */");
//        return str;
//    }

    /**
     * set get 方法
     */
    /*public StringBuilder method(String indentation, String filed, String clazz) {
        StringBuilder str = new StringBuilder();
        String name = filed.substring(0, 1).toUpperCase() + filed.substring(1);

        str.append(indentation).append("public void set").append(name).append("(").append(clazz).append(" ").append(filed).append(") { ");
        str.append(indentation).append("\tthis.").append(filed).append(" = ").append(filed).append(";");
        str.append(indentation).append("}");

        str.append(indentation);

        str.append(indentation).append("public ").append(clazz).append(" get").append(name).append("() { ");
        str.append(indentation).append("\treturn ").append(filed).append(";");
        str.append(indentation).append("}");

        return str;
    }*/

    /**
     * string 方法
     */
    /*public StringBuilder methodStr(String indentation, String name, List<TableDto> list) {
        StringBuilder str = new StringBuilder();

        str.append(indentation).append("@Override");
        str.append(indentation).append("public String toString() {");
        str.append(indentation).append("\treturn \"").append(name).append(" {\" +");
        for (int i=0; i<list.size(); i++) {
            TableDto dto = list.get(i);
            str.append(indentation).append("\t\t");
            str.append(i == 0 ? "\"" : "\", ");
            str.append(dto.getColumnName()).append(" = \" + ").append(dto.getColumnName()).append(" + ");
        }
        str.append(indentation).append("\t\t\"} \" + super.toString();");
        str.append(indentation).append("}");

        return str;
    }*/
}
